﻿using System;
using ZyGames.Framework.Game.Contract;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Tools;
using System.Text.RegularExpressions;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 验证手机号是否可以注册
	/// </summary>
	public class Action10010 : BaseAction
	{
		private string phoneNum;
		private bool isCanRegiste = false;
		private string _log = string.Empty;

		public Action10010(HttpGet actionGetter)
			: base((short)ActionType.DZCheckPhoneNum, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetString("PhoneNum", ref phoneNum))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			try
			{
				Regex rx = new Regex(@"^0{0,1}(13[4-9]|15[7-9]|15[0-2]|18[7-8])[0-9]{8}$");
				if (!rx.IsMatch(phoneNum))
				{
					_log = "手机号不合法";
					isCanRegiste = false;
					return true;
				}
				isCanRegiste = !GameTable.Current.CheckPhoneIsRegisted(phoneNum);
				return true;
			}
			catch (Exception ex)
			{
				Tool.WriteErrorLine("10010消息异常:" + ex.ToString());
				_log = "消息异常";
				isCanRegiste = false;
				return true;
			}
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(isCanRegiste);
			this.PushIntoStack(_log);
		}
	}
}
